package com.aaa.vegetablemarketexpress.controller;

import com.aaa.vegetablemarketexpress.entity.Variety;
import com.aaa.vegetablemarketexpress.service.VarietyService;
import com.aaa.vegetablemarketexpress.util.Page;
import com.aaa.vegetablemarketexpress.util.Result;
import com.aaa.vegetablemarketexpress.util.ResultUtil;
import com.github.pagehelper.PageInfo;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @FileName: VarietyController
 * @Description:
 * @Author: qxh
 * @CreateTime: 2025/9/8 12:54
 * @Version: 1.0.0
 */
@RestController
@RequestMapping("/variety")
@Log4j2
public class VarietyController extends ResultUtil {
    @Resource
    private VarietyService varietyService;
    /**
     * 根据VarietyId查询商品品类
     * @param varietyId
     * @return
     */
    @GetMapping("/queryByVarietyId")
    public Result queryByVarietyId(Long varietyId){
        return ResultUtil.success(varietyService.queryByVarietyId(varietyId));
    }
    /**
     * 分页查询商品品类
     * @param page
     * @return
     */
    @PostMapping("/queryByParam")
    public Result queryByParam(@RequestBody Page<Variety> page){
        log.info("开始执行分页查询");
        PageInfo pageInfo = varietyService.queryByParam(page);
        log.info("分页查询结束");
        return ResultUtil.success(pageInfo);
    }
    /**
     * 根据VarietyName查询商品品类
     * @param varietyName
     * @return
     */
    @GetMapping("/queryByVarietyName")
    public Result queryByVarietyName(@RequestBody String varietyName){
        return ResultUtil.success(varietyService.queryByVarietyName(varietyName));
    }
    /**
     * 添加商品品类
     * @param variety
     * @return
     */
    @PostMapping("/insertVariety")
    public Result insertVariety(@RequestBody Variety variety){
        return ResultUtil.success(varietyService.insertVariety(variety));
    }
    /**
     * 修改商品品类
     * @param variety
     * @return
     */
    @PostMapping("/updateVariety")
    public Result updateVariety(@RequestBody Variety variety){
        return ResultUtil.success(varietyService.updateVariety(variety));
    }
    /**
     * 删除商品品类
     * @param varietyId
     * @return
     */
    @DeleteMapping("/deleteVariety")
    public Result deleteVariety(Long varietyId){
        return ResultUtil.success(varietyService.deleteVariety(varietyId));
    }
    /**
     * 检查商品品类是否被使用
     * @param varietyId
     * @return
     */
    @GetMapping("/checkVarietyUsed")
    public Result checkVarietyUsed(Long varietyId){
        return ResultUtil.success(varietyService.checkVarietyUsed(varietyId));
    }
    /**
     * 修改商品品类状态
     * @param varietyId
     * @param status
     * @return
     */
    @PostMapping("/updateVarietyStatus")
    public Result updateVarietyStatus( Long varietyId, String status){
        return ResultUtil.success(varietyService.updateVarietyStatus(varietyId, status));
    }
    /**
     * 查询所有正常商品品类
     * @return
     */
    @GetMapping("/queryAllNormalVariety")
    public Result queryAllNormalVariety(){
        return ResultUtil.success(varietyService.queryAllNormalVariety());
    }

}
